package primetest.faces;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;


import primetest.dto.NewsDto;

public class NewsListModel extends ListDataModel<NewsDto> implements SelectableDataModel<NewsDto> {

	public NewsListModel(List<NewsDto> newsList){
		super(newsList);
	}

	@Override
	public NewsDto getRowData(String rowKey) {
		@SuppressWarnings("unchecked")
		List<NewsDto> newsList = (List<NewsDto>)getWrappedData();
		for (NewsDto newsDto : newsList) {
			if(newsDto.getKey().equals(rowKey)){
				return newsDto;
			}
		}
		return null;
	}

	@Override
	public Object getRowKey(NewsDto newsDto) {
		return newsDto.getKey();
	}

}
